/**
 * 
 */
package br.com.ctm.advogadope.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlRootElement;

import br.com.framework.persistencia.model.AuditedEntity;

/**
 * @author Cleber
 * 
 */
@Entity
@Table(name="ADVOGADO", uniqueConstraints = {
	@UniqueConstraint(columnNames={"numeroOab", "ufOab"}, name = "uk_advogado_numerooab_ufoab")
})
@XmlRootElement
public class Advogado extends AuditedEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Usuario usuario;
	private Set<Processo> processos = new HashSet<Processo>();
	
	/*private String nome;
	private String cpf;
	private String numeroOab;
	private Uf ufOab;
	private String tipoOab;*/

	/**
	 * 
	 */
	public Advogado() {
	}
	
	@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ_ADVOGADO")
	@SequenceGenerator(name="SEQ_ADVOGADO", sequenceName="SEQ_ADVOGADO", allocationSize=1, initialValue=0)
	@Column(name = "ID_ADVOGADO")
	@XmlID
	public Long getId() {
		return super.getId();
	}
	
	/**
	 * @return the numeroOab
	 *//*
	@Column(name = "NUMERO_OAB", length = 7, nullable = false)
	@Pattern(regexp = "\\d{1,7}", message = "{advogado.numeroOab.invalido}")
	public String getNumeroOab() {
		return numeroOab;
	}

	*//**
	 * @param numeroOab the numeroOab to set
	 *//*
	public void setNumeroOab(String oab) {
		this.numeroOab = oab;
	}

	
	@ManyToOne(targetEntity = Uf.class, optional = false)
	@JoinColumn(name="ID_UF_OAB", nullable = false)
	@NotNull(message = "{advogado.ufOab.obrigatoria}")
	public Uf getUfOab() {
		return ufOab;
	}

	public void setUfOab(Uf ufOab) {
		this.ufOab = ufOab;
	}

	*//**
	 * @return the tipoOab
	 *//*
	@Column(name = "TIPO_OAB", length = 7, nullable = false)
	@NotNull(message = "{advogado.tipoOab.obrigatorio}")
	@Pattern(regexp = "[A-Z]{1}", message = "{advogado.tipoOab.invalido}")
	public String getTipoOab() {
		return tipoOab;
	}

	*//**
	 * @param tipoOab the tipoOab to set
	 *//*
	public void setTipoOab(String tipoOab) {
		this.tipoOab = tipoOab;
	}

	*//**
	 * @return the nome
	 *//*
	@Column(name = "NOME", length = 255, nullable = false)
	@Size(min = 1, max = 255, message = "{geral.campo.texto.tamanhoInvalido}")
	public String getNome() {
		return nome;
	}

	*//**
	 * @param nome the nome to set
	 *//*
	public void setNome(String nome) {
		this.nome = nome;
	}

	*//**
	 * @return the cpf
	 *//*
	@Column(name = "CPF", length = 11, nullable = false)
	@CPF(formatted = false, message = "{geral.campo.cpf.invalido}")
	@NotNull(message = "{geral.campo.cpf.obrigatorio}")
	public String getCpf() {
		return cpf;
	}

	*//**
	 * @param cpf the cpf to set
	 *//*
	public void setCpf(String cpf) {
		this.cpf = cpf;
	}*/

	/**
	 * @return the usuario
	 */
	@OneToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
	@JoinColumn(name="ID_USUARIO")
	@XmlIDREF
	public Usuario getUsuario() {
		return usuario;
	}

	/**
	 * @param usuario the usuario to set
	 */
	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	/**
	 * @return the processos
	 */
	@ManyToMany(targetEntity=Processo.class, fetch = FetchType.LAZY)
	@JoinTable(name = "ADVOGADO_PROCESSO", 
		joinColumns = @JoinColumn(name = "ID_ADVOGADO", referencedColumnName = "ID_ADVOGADO"), 
		inverseJoinColumns = @JoinColumn(name = "ID_PROCESSO", referencedColumnName = "ID_PROCESSO"))
	@XmlIDREF
	public Set<Processo> getProcessos() {
		return processos;
	}

	/**
	 * @param processos the processos to set
	 */
	public void setProcessos(Set<Processo> processos) {
		this.processos = processos;
	}
	
	/**
	 * @param processo
	 */
	public void addProcesso(Processo processo) {
		if (getProcessos() == null) {
			setProcessos(new HashSet<Processo>());
		}
		getProcessos().add(processo);
	}
}
